<template>
    <div class="index-container">
        <!-- 顶部轮播图区域 -->
        <div class="banner-section">
            <ElCarousel
                v-if="getSwiperData.enabled"
                class="main-banner"
                trigger="click"
                height="500px"
                indicator-position="outside"
            >
                <ElCarouselItem v-for="item in showList" :key="item">
                    <NuxtLink :to="item.link.path" target="_blank">
                        <ElImage
                            class="banner-image"
                            :src="item.image"
                            fit="cover"
                        />
                    </NuxtLink>
                </ElCarouselItem>
            </ElCarousel>
        </div>

        <!-- 产品展示区域 - 移动到这里 -->
        <div class="section product-showcase">
            <div class="section-header">
                <h2 class="section-title">产品中心</h2>
                <NuxtLink to="/products" class="view-more">查看更多 <el-icon><ArrowRight /></el-icon></NuxtLink>
            </div>
            <div class="product-grid-featured">
                <div v-for="(item, index) in featuredProducts.slice(0, 2)" :key="index" class="product-card-featured">
                    <NuxtLink :to="`/products/${item.id}`">
                        <div class="product-content">
                            <div class="product-image-featured">
                                <ElImage :src="item.image" fit="cover" />
                                <div class="category-tag" v-if="item.categoryId">
                                    {{ item.categoryId }}
                                </div>
                            </div>
                            <div class="product-info-featured">
                                <h3 class="product-title">{{ item.name }}</h3>
                                <p class="product-desc">{{ item.description }}</p>
                                <el-button class="view-detail-btn" type="primary" size="small">查看详情</el-button>
                            </div>
                        </div>
                    </NuxtLink>
                </div>
            </div>
        </div>

        <!-- 企业简介部分 -->
        <div class="section company-intro">
            <div class="section-header">
                <h2 class="section-title">企业简介</h2>
            </div>
            <div class="company-content">
                <div class="company-text full-width">
                    <h3>关于齐远</h3>
                    <p>杭州齐远医药科技有限公司成立于2024年，是一家致力于革新生物化学技术、突破国外高新生物化学原料合成技术壁垒的新兴企业，公司创始人翁德英抱<span style="color:red;">以人为本，科技为先</span>义、带着"三千越甲可吞吴，百二秦关终属楚"的决心，历经三年零六个月二十五天，在刀与火的洗礼下，成功的合成：113711-77-6  Z-D-ARG-GLY-ARG-PNA▪2 HCL，Xa因子发色底物S-2765，原料价格从进口5万元/克到现在1000元/克。给中国乃至全世界人民的外体医学诊断带来了福音。</p>
                </div>
            </div>
        </div>

        <!-- 企业文化部分 -->
        <div class="section company-culture">
            <div class="section-header">
                <h2 class="section-title">企业文化</h2>
            </div>
            <div class="culture-content">
                <div class="culture-icon">
                    <i class="el-icon-s-flag"></i>
                </div>
                <div class="culture-text">
                    <p>以人为本，研发、制造、销售及传播专业创新的医药产品和知识，改善社会的医疗效能，促进人类健康事业的进步</p>
                </div>
            </div>
        </div>

        <!-- 总经理致辞部分 -->
        <div class="section ceo-speech">
            <div class="section-header">
                <h2 class="section-title">总经理致辞</h2>
            </div>
            <div class="speech-content">
                <div class="speech-text full-width">
                    <p>感谢每一位正在浏览本网站的朋友，谢谢您对齐远医药的关心。</p>
                    <p>回顾齐远的成长历程，我们始终秉承以"专业创新"为核心竞争力的发展理念，在生物化学等领域不断推出高性价比产品，在医药器械领域打破国际优势技术封锁。广大客户对齐远的认可，不仅促进了企业的成长，更坚定了我们继续开发及原创产品的决心。对于员工，齐远医药是一个富有人文关怀且能够实现自我价值的公平舞台；对于合作伙伴，齐远药业是可以实现优质价值强强联合、互利共赢的选择；对于社会大众，齐远致力于带来健康与专业的服务。</p>
                    <p>感谢所有给予我们关心与帮助的朋友。</p>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ElCarousel, ElCarouselItem, ElImage, ElButton } from 'element-plus'
import { ArrowRight } from '@element-plus/icons-vue'
import { getIndex } from '@/api/shop'
import { useAppStore } from '~~/stores/app'
import { getProductList } from '@/api/product'

const appStore = useAppStore()
const { data: pageData } = await useAsyncData(() => getIndex(), {
    default: () => ({
        all: [],
        hot: [],
        new: [],
        page: {}
    })
})

const getSwiperData = computed(() => {
    try {
        const data = JSON.parse(pageData.value.page.data)
        console.log(data)
        return data.find((item) => item.name === 'pc-banner')?.content
    } catch (error) {
        return {}
    }
})

const showList = computed(() => {
    return getSwiperData.value?.data || []
})

// 替换模拟数据部分
const featuredProducts = ref([])

// 获取产品数据
const fetchProducts = async () => {
  try {
    const res = await getProductList({
      pageNo: 1,
      pageSize: 12,
      sort: 'newest'
    })
    featuredProducts.value = res.lists
  } catch (error) {
    console.error('获取产品数据失败', error)
  }
}

// 在页面加载时获取数据
onMounted(() => {
  fetchProducts()
})
</script>

<style lang="scss" scoped>
.index-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

.banner-section {
    margin-bottom: 60px;  // 增加底部间距
}

.main-banner {
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);

    // 调整指示器样式
    :deep(.el-carousel__indicators) {
        margin-top: 20px;  // 增加与轮播图的距离
        
        .el-carousel__button {
            width: 30px;  // 增加指示器宽度
            height: 3px;  // 设置指示器高度
            margin: 0 8px;  // 增加指示器之间的间距
            border-radius: 2px;
        }
    }
}

.banner-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.section {
    margin-bottom: 80px;  // 增加section之间的间距
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 15px;
}

.section-title {
    font-size: 24px;
    font-weight: 600;
    color: #333;
    margin: 0;
    position: relative;
    padding-left: 15px;
    
    &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 4px;
        height: 20px;
        background-color: var(--el-color-primary);
        border-radius: 2px;
    }
}

.view-more {
    display: flex;
    align-items: center;
    color: var(--el-color-primary);
    font-size: 14px;
    text-decoration: none;
    
    .el-icon {
        margin-left: 5px;
        transition: transform 0.3s;
    }
    
    &:hover .el-icon {
        transform: translateX(3px);
    }
}

.product-grid-featured {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.product-card-featured {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s, box-shadow 0.3s;
    
    &:hover {
        transform: translateY(-5px);
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    }
    
    a {
        text-decoration: none;
        color: inherit;
    }
}

.product-content {
    display: flex;
    height: 200px;
}

.product-image-featured {
    width: 300px;
    position: relative;
    overflow: hidden;
    
    .el-image {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    
    .category-tag {
        position: absolute;
        top: 20px;
        left: -35px;
        background-color: var(--el-color-primary);
        color: white;
        padding: 6px 40px;
        transform: rotate(-45deg);
        font-size: 12px;
        z-index: 1;
        text-align: center;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
}

.product-info-featured {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.view-detail-btn {
    align-self: flex-start;
    margin-top: 10px;
}

.product-image {
    height: 200px;
    overflow: hidden;
    
    .el-image {
        width: 100%;
        height: 100%;
    }
}

.product-info {
    padding: 15px;
}

.product-title {
    font-size: 16px;
    margin: 0 0 10px;
    color: #333;
    font-weight: 600;
}

.product-desc {
    font-size: 14px;
    color: #666;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    height: 40px;
}

.news-grid {
    display: flex;
    gap: 30px;
}

.news-main {
    flex: 2;
}

.news-side {
    flex: 1;
}

.about-section {
    background: #f9f9f9;
    padding: 30px;
    border-radius: 8px;
}

.about-content {
    display: flex;
    gap: 30px;
    align-items: center;
}

.about-image {
    flex: 1;
    max-width: 400px;
    
    .el-image {
        width: 100%;
        border-radius: 8px;
        overflow: hidden;
    }
}

.about-text {
    flex: 1;
    
    h3 {
        font-size: 20px;
        margin: 0 0 15px;
        color: #333;
    }
    
    p {
        color: #666;
        line-height: 1.6;
        margin-bottom: 15px;
    }
}

@media (max-width: 768px) {
    .news-grid,
    .about-content {
        flex-direction: column;
    }
    
    .about-image {
        max-width: 100%;
        margin-bottom: 20px;
    }
}

// 企业简介样式
.company-content, .speech-content {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    
    @media (max-width: 768px) {
        flex-direction: column;
    }
}

.company-image, .speech-image {
    flex: 1;
    max-width: 400px;
    
    .el-image {
        width: 100%;
        border-radius: 8px;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    @media (max-width: 768px) {
        max-width: 100%;
        margin-bottom: 20px;
    }
}

.company-text.full-width, .speech-text.full-width {
    flex: 1;
    max-width: 100%;
    background-color: #f8f9fa;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.company-text, .speech-text {
    flex: 1.5;
    
    h3 {
        font-size: 20px;
        margin: 0 0 15px;
        color: #333;
    }
    
    p {
        color: #333;
        line-height: 1.8;
        margin-bottom: 15px;
        text-align: justify;
    }
}

// 企业文化样式
.culture-content {
    background-color: #f8f9fa;
    padding: 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.culture-icon {
    font-size: 48px;
    color: var(--el-color-primary);
    margin-bottom: 20px;
}

.culture-text {
    p {
        font-size: 18px;
        font-weight: 500;
        color: #333;
        line-height: 1.8;
        max-width: 800px;
        margin: 0 auto;
    }
}
</style>
